<template>
	<view class="content">
		<image class="logo" src="/static/logo.png"></image>
		<view class="text-area">
			<text class="title">{{title}}</text>
		</view>
		<button @click="pickImg">添加图片</button>
		<image :src="imgSrc" mode=""></image>
		<p>消费类型：{{ocrResult[0].kind_description}}</p>
		<p>消费金额：{{ocrResult[0].item_list[0].value}}</p>
		<p>消费单号：{{ocrResult[0].item_list[1].value}}</p>
		<p>消费时间：{{ocrResult[0].item_list[2].value}}</p>
		<p>消费商户：{{ocrResult[0].item_list[3].value}}</p>
		<p>消费商品：{{ocrResult[0].item_list[4].value}}</p>
	</view>
</template>

<script>
	import {Textin} from '@/config/api.js'
	export default {
		data() {
			return {
				title: 'Hello',
				imgSrc:'',
				ocrResult:[
					{
						kind_description:'default',
						item_list:[
							{
								value:''
							},
							{
								value:''
							},
							{
								value:''
							},
							{
								value:''
							},
							{
								value:''
							},
							]
					
					},
				],
				
			}
		},
		onLoad() {
			
		},
		methods: {
			pickImg(){
				var _this = this;
				uni.chooseImage({
					count:9,
					sizeType:['original','compressed'],
					sourceType:['album','camera'],
					success: async function(res){
						_this.imgSrc = res.tempFilePaths[0];
						console.log(res.tempFiles);
						
						var reader = new FileReader()
						reader.readAsArrayBuffer(res.tempFiles[0]) // 读取成二进制
						reader.onload = function (e) {
							var fileData = this.result;
							console.log(fileData);
								 
							 Textin.getData(fileData).then((res)=>{
								 _this.ocrResult = res.data.result.object_list;
								 console.log( _this.ocrResult);
							 });
							
						}
					}
				})
			}
		}
	}
</script>

<style>
	.content {
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
	}

	.logo {
		height: 200rpx;
		width: 200rpx;
		margin-top: 200rpx;
		margin-left: auto;
		margin-right: auto;
		margin-bottom: 50rpx;
	}

	.text-area {
		display: flex;
		justify-content: center;
	}

	.title {
		font-size: 36rpx;
		color: #8f8f94;
	}
</style>
